/*
 * Created on Oct 9, 2005 7:24:10 AM
 * 
 * $Id: Manager.java,v 1.3 2005/10/11 19:19:15 olu Exp $
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package tripleo.curr;

import java.util.*;

import tripleo.util.Assert;
import tripleo.util.Pair;

public class Manager implements Process {

	private Map states=new Hashtable();
	private Enum init_;
	private ProcessQ q;
	
	public void setInitialState(Enum s) {
		init_=s;
	}

	public void addState(Enum state, Process aProcess, Enum progress) {
		states.put(state, Pair.make(aProcess, progress) );
	}
	
	public void start() {
		q = ProcessQ.defaultInstance();
		run();
	}

	static public final long START = 1;
	
	public void run() {
		Enum X = init_;
		while (X!=null) {
			final Pair object = ((Pair)states.get(X));
			q.send(this, (Process)object.first, START, null);
			X=(Enum) object.second;
		}
	}

	public void rcv(Process aSender, long aMessage, Object aValue) {
		Assert.not_reached();
	}

	final Object sendLock=new Object();
	public Object rcvLock() {
		return sendLock;
	}

	public void fail(Enum aStage, Exception aE) { // Stages
		// TODO Auto-generated method stub
		Assert.not_implemented();
	}

}

